package org.langcom.logic.constraint;

import java.util.ArrayList;
import java.util.List;

public class ConstraintValue<T> extends AbstractConstraint<T> {

	private static final long serialVersionUID = 7865065463883677271L;
	private final T modelValue;
	private final ConstraintType type;

	protected ConstraintValue(String description, String detailedDescription, T modelValue, ConstraintType type) {
		super(description, detailedDescription);
		this.modelValue = modelValue;
		this.type = type;
	}

	public List<T> getValidValues() {
		List<T> result = new ArrayList<T>();
		result.add(modelValue);
		return result;
	}

	public boolean validate(T newValue) {
		switch (type) {
			case EQUAL:
				return modelValue.equals(newValue);
			case LESS:
				return modelValue.equals(newValue);
			case LESS_OR_EQUAL:
				return modelValue.equals(newValue);
			case MORE:
				return modelValue.equals(newValue);
			case MORE_OR_EQUAL:
				return modelValue.equals(newValue);
			case NOT_EQUAL:
				return modelValue.equals(newValue);
		}
		return false;
	}

	public ConstraintType getType() {
		return type;
	}

	@Override
	protected boolean tryOn() throws Exception {
		return false;
	}
}
